package com.example.dwr.gidemo;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.directwebremoting.Browser;
import org.directwebremoting.ScriptSessions;
import org.directwebremoting.ServerContext;
import org.directwebremoting.ServerContextFactory;
import org.directwebremoting.impl.DaemonThreadFactory;

public class Publisher
  implements Runnable
{
  protected Corporations corporations = new Corporations();

  public Publisher()
  {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory());
executor.scheduleAtFixedRate(this, 1L, 1L, TimeUnit.SECONDS);
  }

  public void run()
  {
String contextPath = ServerContextFactory.get().getContextPath();
if (contextPath == null)
{
  return;
}

Browser.withPage(contextPath + "/gi/dwr-oa-gi.html", new Runnable()
{
  public void run()
  {
Corporation corp = corporations.getNextChangedCorporation();
ScriptSessions.addFunctionCall("OpenAjax.hub.publish", new Object[] { "gidemo.corp", corp });
  }
});
  }
}